package com.mall.common.util;

import java.util.Calendar;
import java.util.Random;

public class CodeUtil {

	public static String mallGroupBuyCode(Long userId) {
		Calendar cal = Calendar.getInstance();
		int day = cal.get(Calendar.DATE);
		String strDay = day + "";
		if (day < 10) {
			strDay = getRandom(1, 9) + day;
		}
		int month = cal.get(Calendar.MONTH) + 1;
		String strMonth = month + "";
		if (month < 10) {
			strDay = getRandom(1, 9) + month;
		}
		return getRandom(1000, 9999) + strDay + strMonth + getRandom(1000, 9999) + userId;
	}

	public static String getRandom(int min, int max) {
		Random random = new Random();
		int s = random.nextInt(max) % (max - min + 1) + min;
		return String.valueOf(s);
	}

	public static void main(String[] args) {
		for (int i = 0; i < 100; i++) {
			System.out.println(mallGroupBuyCode(1l));
		}
	}
}
